package cn.ptu.pmaa.service;

import cn.ptu.pmaa.entities.*;
import cn.ptu.pmaa.mapper.StudentMapper;
import cn.ptu.pmaa.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StudentService {

    @Autowired
    DateUtil dateUtil;

    @Autowired(required = false)
    StudentMapper studentMapper;

    //通过预约时间查询教室
    public List<YyClassRoom> getSiteByTime(String fromTime, String toTime , String date){
        return studentMapper.getSiteByTime(fromTime,toTime,date);
    }

    //确定预约教室
    public int yySiteByClassId(Appintment appintment){
        return studentMapper.insertAppintment(appintment);
    }

    //查看预约情况
    public List<Appintment> ckyyqk(String userId){
        return studentMapper.getAppintment(userId);
    }

    //取消预约
    public int qxyy(String userid,String yyid ){
        if (userid.equals(studentMapper.getUserIdByYyid(yyid))){
            return studentMapper.setAppiState(yyid);
        }else{
            return 0;
        }

    }

    //根据教室id查询教室信息
    public ClassRoom getClassroomById(String id){
        return studentMapper.getClassroomById(id);
    }


    //提前结束预约
    public int tqjssy(String userid,String yyid ){
        if (userid.equals(studentMapper.getUserIdByYyid(yyid))){
            return studentMapper.setYyjssj(yyid,dateUtil.myDateTimeToTime(new Date()));
        }else{
            return 0;
        }
    }

    //个人信息修改
    public int grxxxg(Student student){
       return studentMapper.setStudentInfo(student);
    }

}
